﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Collections;
using System.Web.UI.HtmlControls;

public partial class thong_tin_du_an_detail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                int id = ConvertUtility.ToInt32(Request.QueryString["id"]);
                if (id > 0)
                {
                    hidID.Value = id.ToString();
                    Content_Info contentInfo = Content_Info.Find(id);
                    contentInfo.contentVisited += 1;
                    contentInfo.SaveAndFlush();

                    Page.Title = contentInfo.contentTitle;
                    litContent.Text = contentInfo.contentDes;
                    lblDate.Text = ConvertUtility.ConvertDateTimeVN_All(contentInfo.contentDate);
                    lblTit.Text = contentInfo.contentTitle;

                    int catID = ConvertUtility.ToInt32(Request.QueryString["catID"]);
                    if (catID > 0)
                    {
                        hidCatID.Value = catID.ToString();
                        int pageIndex = ConvertUtility.ToInt32(Request.QueryString["page"]);
                        if (pageIndex > 0)
                            bindOtherNews(pageIndex);
                        else
                            bindOtherNews(1);
                    }
                }

            }
        }
        catch (Exception ex) { }
    }
    protected void bindOtherNews(int pageIndex)
    {

        int catID = ConvertUtility.ToInt32(hidCatID.Value);
        int id = ConvertUtility.ToInt32(hidID.Value);
        Conjunction conj = new Conjunction();
        conj.Add(Expression.Eq("contentCatID", Category_Info.Find(catID)));
        conj.Add(Expression.Not(Expression.Eq("id", id)));

        Content_Info[] lstContent = Content_Info.FindAll(Order.Desc("id"), conj);
        repListOther.DataSource = lstContent.Skip((pageIndex - 1) * 40).Take(40);
        repListOther.DataBind();
        seo(catID);

    }
    protected void seo(int catID)
    {
        Category_Info catInfo = Category_Info.Find(catID);
        litPos.Text += "<a href='/thong-tin-du-an/" + catInfo.id + "/" + App_String.getTitleKhongDau(catInfo.catName) + ".html'> " + catInfo.catName + " </a> ";

        Page.Title += catInfo.catMetaTitle;
        //keywords
        HtmlMeta keywords = new HtmlMeta();
        keywords.Name = "keywords";
        keywords.Content = catInfo.catMetaKey;
        Page.Header.Controls.Add(keywords);
        //description
        HtmlMeta descriptions = new HtmlMeta();
        descriptions.Name = "description";
        descriptions.Content = catInfo.catMetaDes;
        Page.Header.Controls.Add(descriptions);
    }
}